package com.lb.bs.client.processor.handle.statics.first;

import com.lb.bs.client.annotation.ProcessorMark;
import com.lb.bs.client.annotation.SingletonMark;
import com.lb.bs.client.repository.StoreCenter;
import com.lb.bs.client.beans.LBItemBean;
import com.lb.bs.client.repository.ScanStaticModel;
import com.lb.bs.client.processor.ProcessorService;
import com.lb.bs.client.processor.enums.ProcessorType;

import java.lang.reflect.Field;
import java.util.Map;

/**
 * program: LB-BS-Client
 * author: bsworld.xie
 * create: 2019-12-11 16:33
 * description:
 */
@SingletonMark
@ProcessorMark(type = ProcessorType.FIRST_TO_INSTANCE)
public class StaticTransform2InstanceProcessor implements ProcessorService<ScanStaticModel> {
    @Override
    public void process(ScanStaticModel scanStaticModel) {
        Map<String, LBItemBean> itemKeyMap = StoreCenter.getInstance().getItemKeyMap();
        for (LBItemBean bean : itemKeyMap.values()) {
            Field field = bean.getField();
            Object originBean = bean.getOriginBean();
            Object value = bean.getValue();
            try {
                field.set(originBean, value);
            } catch (IllegalAccessException e) {

                e.printStackTrace();
            }
        }
    }
}
